package com.wlz.behavioral.observer;

import java.util.ArrayList;
import java.util.List;

public class Liubei implements ILeader,Observable {
    //韩非子是否在吃饭， 作为监控的判断标准
    private boolean isHavingBreakfast = false;
    //韩非子是否在娱乐
    private boolean isHavingFun = false;

    private List<IUndercover> observerList=new ArrayList<IUndercover>();

    //韩非子要吃饭了
    public void haveBreakfast() {
        System.out.println("刘备:开始吃饭了...");
        this.isHavingBreakfast = true;
        this.notifyObservers("刘备开始吃饭了");
    }
    //韩非子开始娱乐了
    public void haveFun() {
        System.out.println("刘备:开始蹦迪了...");
        this.isHavingFun = true;
        this.notifyObservers("刘备开始蹦迪了");
    }

    public boolean isHavingBreakfast() {
        return isHavingBreakfast;
    }

    public void setHavingBreakfast(boolean isHavingBreakfast) {
        this.isHavingBreakfast = isHavingBreakfast;
    }

    public boolean isHavingFun() {
        return isHavingFun;
    }

    public void setHavingFun(boolean isHavingFun) {
        this.isHavingFun = isHavingFun;
    }

    @Override
    public void addObserver(IUndercover observer) {
        observerList.add(observer);
    }

    @Override
    public void deleteObserver(IUndercover observer) {
        observerList.remove(observer);
    }

    @Override
    public void notifyObservers(String context) {
        for(IUndercover observer:observerList){
            observer.report(context);
        }
    }
}